#define BCCWIN
#define DOEXPORT
#include "nodavesimple.h"
#include "openSocket.h"
#include <Windows.h>
#include "plc_link.h"

//#include "interface.h"  
/*quote to interface.h will have conflict issue with datastruct.h*/
#pragma comment(lib, "libnodave.lib")

#define RACK		0
#define SLOT		1
#define PLC_PORT	102

_daveOSserialType fds;
daveInterface *di = NULL;
daveConnection *dc = NULL;

HANDLE plc_mutex = NULL;

int connect_to_plc(char *ip)
{
	int result = FALSE;

	return result;
}

int disconnect_from_plc()
{
	WaitForSingleObject(plc_mutex, INFINITE);
	int result = FALSE;

	ReleaseMutex(plc_mutex);
	return result;
}

int read_from_plc_db(int index, int start, int lens, BYTE *buf)
{
	//if (!IS_PLC_CONNECTED) {
	//	logdlg.log("Link to PLC Error!");
	//	return FALSE;
	//}
	WaitForSingleObject(plc_mutex, INFINITE);
	int result = 0;

	ReleaseMutex(plc_mutex);
	//Sleep(50);
	return result;
}

int write_to_plc_db(int index, int start, int lens, void *buf)
{
	//if (!IS_PLC_CONNECTED) {
	//	logdlg.log("Link to PLC Error!");
	//	return FALSE;
	//}

	WaitForSingleObject(plc_mutex, INFINITE);
	int result = 0;
	BYTE* read = 0;
	

	ReleaseMutex(plc_mutex);
	//Sleep(50);
	return result;
}
